<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 200px;
            height: 200px;
            background-color: #CCC;
            text-align: center;
            color: white;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <div class="box">
        <p>0</p>
    </div>

    <script src="/js/lodash.js"></script>
    <script>
        const box = document.querySelector('.box')
        let i = 0
        function wei() {
            box.innerHTML = i++
        }
        // box.addEventListener('mousemove', on)

        // lodash库实现防抖
        // box.addEventListener('mousemove', _.debounce(wei, [wait = 500]))



        // 手写防抖函数
        function docuon(fu, i) {
            let timer
            return function () {
                if (timer) clearTimeout(timer)
                timer = setTimeout(function () {
                    fu()
                }, i)
            }
            //return 返回一个匿名函数
        }
        box.addEventListener('mousemove', docuon(wei, 500))

        docuon(wei, 500) //调用函数
        docuon(wei, 500) = function () { 1, 2, 3 }

    </script>
</body>

</html>